package com.dailywork.basepro.thread.local;

public class ConnThreadLocal {

    /**
     * ThreadLocalֻ���һ���߳���Ч,��һ���߳�����Ч,δ��Ҳ����һ���߳���Ч
     */
    public static ThreadLocal<String> th = new ThreadLocal<String>();

    public void setTh(String Value) {
        th.set(Value);
    }

    public void getTh() {
        System.out.println(Thread.currentThread().getName() + ":" + this.th.get());
    }

    public static void main(String[] args) {
        final ConnThreadLocal ct = new ConnThreadLocal();
        Thread t1 =
                new Thread(
                        new Runnable() {
                            @Override
                            public void run() {
                                // TODO Auto-generated method stub
                                ct.setTh("����");
                                ct.getTh();
                            }
                        },
                        "t1");

        Thread t2 =
                new Thread(
                        new Runnable() {
                            @Override
                            public void run() {
                                // TODO Auto-generated method stub
                                try {
                                    Thread.sleep(1000);
                                    ct.getTh();
                                } catch (InterruptedException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }
                        },
                        "t2");

        t1.start();
        t2.start();
    }
}
